//
//  SegmentControlView.m
//  qiuShiJiangHu
//
//  Created by xalo on 16/1/23.
//  Copyright © 2016年 糗事江湖项目组. All rights reserved.
//

#import "SegmentControlView.h"

@implementation SegmentControlView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        CGFloat totalWith=self.frame.size.width;
        CGFloat totalHeight=self.frame.size.height;
        //给segment赋值
        
        self.segment=[[UISegmentedControl alloc] initWithItems:@[@"纯文",@"视频",@"纯图",@"精华"]];
        self.segment.tintColor=[UIColor whiteColor];
        self.segment.frame=CGRectMake(0, 0, totalWith, totalHeight);
        //设置normal下的背景图片
        [self.segment setBackgroundImage:[UIImage imageNamed:@"underline_Unselected@2x"] forState:(UIControlStateNormal) barMetrics:(UIBarMetricsDefault)];
       //设置选择状态下的背景图片
        [self.segment setBackgroundImage:[UIImage imageNamed:@"underline_selected@2x"] forState:(UIControlStateSelected) barMetrics:(UIBarMetricsDefault)];
        //设置高亮状态下的背景图片
        [self.segment setBackgroundImage:[UIImage imageNamed:@"underline_selected@2x"] forState:(UIControlStateHighlighted) barMetrics:(UIBarMetricsDefault)];
        //设置分段控制器的字体属性
        //normal状态下
        NSDictionary *normalDic=@{NSForegroundColorAttributeName:[UIColor blackColor]};
        [self.segment setTitleTextAttributes:normalDic forState:(UIControlStateNormal)];
        //选择状态下
        NSDictionary *selectDic=@{NSForegroundColorAttributeName:[UIColor colorWithRed:222/225.0 green:105/255.0 blue:140/255.0 alpha:1.0]};
        [self.segment setTitleTextAttributes:selectDic forState:(UIControlStateSelected)];
        //高亮状态下
        [self.segment setTitleTextAttributes:selectDic forState:(UIControlStateHighlighted)];
        self.segment.selectedSegmentIndex=0;
        [self addSubview:self.segment];
        
    }
    return self;

}

@end
